import { authorityHttp, defHttp } from '/@/utils/http/axios';
import {
  getMenuListResultModel,
  getRoleMenuListResultModel,
  getSaaSUserMenuListResultModel,
  RoleMenuParams,
  SaaSUserMenuParams,
  UserMenuParams,
} from './model/menuModel';

enum Api {
  GetSaaSAccessibleMenu = '/v1/user/menu/accessible',

  GetMenuList = '/getMenuList',

  GetRoleMenu = '/getRoleMenu',

  GetUserMenu = '/user/getMenu',

  GetPermission = '/v1/user/menu/accessibleForElement',
}

/**
 * @description: Get user menu based on id
 */

export const getMenuList = () => {
  return defHttp.get<getMenuListResultModel>({ url: Api.GetMenuList });
};

/**
 * @description: Get role menu based on roleList
 */
export const getRoleMenu = (params: RoleMenuParams) => {
  return defHttp.get<getRoleMenuListResultModel>({
    url: Api.GetRoleMenu,
    params,
  });
};

export const getUserMenu = (params: UserMenuParams) => {
  return defHttp.get<getRoleMenuListResultModel>({
    url: Api.GetUserMenu,
    params,
  });
};

export const getSaaSAccessibleMenu = (params: SaaSUserMenuParams) => {
  // 请求用户可访问菜单
  return authorityHttp.get<getSaaSUserMenuListResultModel>({
    url: Api.GetSaaSAccessibleMenu,
    params,
  });
};
export const getPermission = (params: SaaSUserMenuParams) => {
  // 请求用户可访问菜单
  return authorityHttp.get<string[]>({
    url: Api.GetPermission,
    params,
  });
};
